package cfca.seal.web.tag;

import cfca.seal.system.Env;
import cfca.seal.util.IdentificationTypeUtil;
import cfca.seal.util.StringUtil;
import cfca.seal.web.tag.base.TemplateDirectiveModelBase;
import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import org.springframework.stereotype.Component;

@Component
public class IdentificationNameTag extends TemplateDirectiveModelBase
{
  public String process(Environment env, Map paramsMap, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException
  {
    String identificationName = "";
    IdentificationTypeUtil identificationType = new IdentificationTypeUtil(Env.configDir + File.separator + "identificationType.properties");

    Enumeration en = identificationType.getPropertyNames();
    while (en.hasMoreElements()) {
      String key = (String)en.nextElement();
      String value = identificationType.getPropertyValueByKey(key);

      if ((StringUtil.isNotEmpty(this.elementValue)) && (key.equals(this.elementValue))) {
        identificationName = value;
      }
    }

    return identificationName;
  }
}